///<reference path="file://D:/Android/touch/sencha-touch-all-debug-w-comments.js" />
Ext.define('Contact', {
    extend: 'Ext.data.Model',
    fields: ['firstName', 'lastName']
});
var form;
Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,

    onReady: function () {

        Ext.regModel('Product', {
            fields: [
                { name: 'name', type: 'string' },
                { name: 'description', type: 'string' },
                { name: 'price', type: 'float' },
                { name: 'image_url', type: 'string' },
                { name: 'in_stock', type: 'boolean' }
            ]
        });

        Ext.regModel('car', {
            fields: [
                { name: 'manufacture', type: 'string' },
                { name: 'model', type: 'string' },
                { name: 'price', type: 'decimal' }

            ]
        });

        var productsList = new Ext.DataView({
            store: new Ext.data.Store({
                model: 'car',
                proxy: {
                    type: 'ajax',
                    url: 'cars.json',
                    reader: {
                        type: 'json',
                        root: 'data'
                    }
                },
                autoLoad: true
            }),
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div class="item">',
                        '<img src="{manufacture}" />',
                        '<div class="button">Buy</div>',
                    '</div>',
                '</tpl>'
            ),
            itemSelector: "div.item",
            fullscreen: true

        });
    }
});
var store = Ext.create('Ext.data.Store', {
    model: 'Contact',
    sorters: 'lastName',

    getGroupString: function (record) {
        return record.get('lastName')[0];
    },

    data: [
       { firstName: 'Tommy', lastName: 'Maintz' },
       { firstName: 'Rob', lastName: 'Dougan' },
       { firstName: 'Ed', lastName: 'Spencer' },
       { firstName: 'Jamie', lastName: 'Avins' },
       { firstName: 'Aaron', lastName: 'Conran' },
       { firstName: 'Dave', lastName: 'Kaneda' },
       { firstName: 'Jacky', lastName: 'Nguyen' },
       { firstName: 'Abraham', lastName: 'Elias' },
       { firstName: 'Jay', lastName: 'Robinson' },
       { firstName: 'Nigel', lastName: 'White' },
       { firstName: 'Don', lastName: 'Griffin' },
       { firstName: 'Nico', lastName: 'Ferrero' },
       { firstName: 'Nicolas', lastName: 'Belmonte' },
       { firstName: 'Jason', lastName: 'Johnston' }
   ]
});

Ext.onReady(function () {
    Ext.create('Ext.field.Text', {
        value: 'Button',

        renderTo: Ext.get('div2')

    });

    Ext.create('Ext.Button', {
        text: 'Button',
        fullscreen: true,
        renderTo: Ext.get('div2')

    });
    var list = Ext.create('Ext.List', {
        fullscreen: true,
        renderTo: Ext.get('div2'),
        itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
        store: store
    });
    Ext.create('Ext.DataView', {
        fullscreen: true,
        cls: 'twitterView',
        store: {
            autoLoad: true,
            fields: ['from_user', 'text', 'profile_image_url'],

            proxy: {
                type: 'jsonp',
                url: 'http://search.twitter.com/search.json?q=Sencha Touch',

                reader: {
                    type: 'json',
                    root: 'results'
                }
            }
        },

        itemTpl: '<img src="{profile_image_url}" /><h2>{from_user}</h2><p>{text}</p><div style="clear: both"></div>'
    });
    var email = Ext.create('Ext.form.Email', {
        label: 'Email address',
        value: 'prefilled@email.com',
        required: true,
        renderTo: Ext.get('divgrid')
    });



     form = Ext.create('Ext.form.Panel', {
         fullscreen: true, 
         standardSubmit:true,
        items: [
        {
            xtype: 'textfield',
            name: 'name',
            label: 'Name',
            equired: true
        },
        {
            xtype: 'emailfield',
            name: 'email',
            label: 'Email',
                 maxLength:5
        },
        {
            xtype: 'passwordfield',
            name: 'password',
            label: 'Password'
        },
        {
            xtype: 'button',
            text: 'submit',
            handler:submitfields
        }
    ]
    });

    form.show();

});


function submitfields() {

    Ext.define('MyApp.model.User', {
        fields: ['name', 'email', 'password']
    });

    var ed = Ext.create('MyApp.model.User', {
        name: 'Ed',
        email: 'ed@sencha.com',
        password: 'secret'
    });

    form.setRecord(ed);

}
function failureHandler(from,result) {
    alert(result);
}
 
  function checkEmail() {
      Ext.get("txtEmail").validationMessage = "hello email.";
      Ext.get("txtEmail").checkValidity();

  }